package cn.zbh._01_sync;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Product {
    public static void main(String[] args) throws Exception {
// 实例化消息生产者Producer
        DefaultMQProducer producer = new DefaultMQProducer("sync-product");
// 设置NameServer的地址
        producer.setNamesrvAddr("localhost:9876");

        // 启动Producer实例
        producer.start();
        // 创建消息，并指定Topic，Tag和消息体
        Message hello = new Message("product-topic", "hello", "爱你哟".getBytes(StandardCharsets.UTF_8));
        SendResult send = producer.send(hello);
        System.out.println(send);

        // 如果不再发送消息，关闭Producer实例。

        producer.shutdown();


    }
}
